package chapter16;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/23 15:53
 */
public class Counter {
    private final Lock lock = new ReentrantLock();
    private volatile int count;

    public void increment() {
        lock.lock();
        try {
            count++;
        } finally {
            lock.unlock();
        }
    }

    public int getCount() {
        return count;
    }
}
